<template>
  <div>
    <!-- 把整体看作一个table -->
    <el-col class="el-col">
      <!-- 头部区域 -->
      <div class="colhead">
        <el-tag>专业管理</el-tag>
        <!-- <svg-icon icon-class="mark" style="margin-left:10px; "></svg-icon> -->
        <el-input placeholder="搜索" style="width:100px;display:inline-block;margin-left:200px;"></el-input>
      </div>

      <el-main>
        <el-input v-model="select_word" placeholder="专业" style="display:inline-block;width:150px;"></el-input>
        <el-button type="primary" style="margin-left:10px;" @click="baonewAdd">新增</el-button>
        <el-button type="warning" @click="baodeleteAll">批量删除</el-button>
      </el-main>
      <el-table
        border
        ref="multipleTable"
        tooltip-effect="dark"
        @select="select"
        @select-all="select"
        :data="data.slice((currentPage-1)*pagesize,currentPage*pagesize)"
      >
        <el-table-column type="selection"></el-table-column>
        <el-table-column prop="profession" label="专业" width="100%"></el-table-column>
        <el-table-column prop="collage_name" label="隶属学院"></el-table-column>
        <el-table-column prop="school_name" label="隶属学校"></el-table-column>
        <el-table-column prop="status" label="状态"></el-table-column>
        <el-table-column prop="profession_if_Enabled" label="可选操作"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              @click="handleClick(scope.$index,scope.row)"
              icon="el-icon-bottom"
              type="text"
              size="small"
            >查看</el-button>
            <el-button
              @click="handleEdit(scope.$index, scope.row)"
              icon="el-icon-edit"
              type="text"
              size="small"
            >编辑</el-button>
            <el-button
              @click="handleDelete(scope.$index, scope.row)"
              icon="el-icon-circle-close"
              type="text"
              size="small"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- </el-container> -->


      <el-footer style="margin-top:20px;">
        <template>
          <div class="block">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10, 20, 40]"
              :page-size="pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="data.length"
            ></el-pagination>
          </div>
        </template>
      </el-footer>
    </el-col>

    <!-- ----查看专业信息---- -->
    <el-dialog title="查看个人信息" :visible.sync="bao1look">
      <el-form :model="LookInfo">
        <el-form-item label="专业">
          <el-input style="display:inline-block;width:33%;" v-model="bao1look.profession"></el-input>
        </el-form-item>
        <el-form-item label="隶属学院">
          <el-input style="display:inline-block;width:33%;" v-model="bao1look.collage_name"></el-input>
        </el-form-item>
        <el-form-item label="隶属学校">
          <el-input style="display:inline-block;width:33%;" v-model="bao1look.school_name"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-input style="display:inline-block;width:33%;" v-model="bao1look.status"></el-input>
        </el-form-item>
        <el-form-item label="可选操作">
          <el-input style="display:inline-block;width:33%;" v-model="bao1look.profession_is_Enabled"></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 修改专业信息 -->
    <el-dialog title="修改信息" :visible.sync="bao1edit">
      <el-form :model="EditInfo" ref="EditInfo">
        <el-form-item label="专业">
          <el-input style="display:inline-block;width:33%;" v-model="bao1edit.profession"></el-input>
        </el-form-item>
        <el-form-item label="隶属学院">
          <el-input style="display:inline-block;width:33%;" v-model="bao1edit.collage_name"></el-input>
        </el-form-item>
        <el-form-item label="隶属学校">
          <el-input style="display:inline-block;width:33%;" v-model="bao1edit.school_name"></el-input>
        </el-form-item>
        <el-form-item label="状态">
          <el-input style="display:inline-block;width:33%;" v-model="bao1edit.status"></el-input>
        </el-form-item>
        <el-form-item label="可选操作">
          <el-input style="display:inline-block;width:33%;" v-model="AddInfo.profession_is_Enabled"></el-input>
        </el-form-item>
      </el-form>
      <!-- 按钮确定和取消 -->
      <span slot="footer">
        <el-button type="primary" @click.native="bao1editSure">确定</el-button>
        <el-button @click.native="bao1edit = false">取消</el-button>
      </span>
    </el-dialog>
    <!-- 删除确定按钮 -->
    <el-dialog title="是否删除信息" :visible.sync="bao1detele">
      <!-- 按钮确定和取消 -->
      <span slot="footer">
        <el-button type="primary" @click.native="bao1DeteleSure">确定</el-button>
        <el-button @click.native="bao1detele = false">取消</el-button>
      </span>
    </el-dialog>

    <!-- ----新增信息---- -->
    <el-dialog title="新增个人信息" :visible.sync="bao1newadd">
      <el-form :model="AddInfo" ref="AddInfo">
        <el-form-item label="专业">
          <el-input style="display:inline-block;width:33%;" v-model="AddInfo.profession"></el-input>
        </el-form-item>
        <el-form-item label="隶属学院">
          <el-input style="display:inline-block;width:33%;" v-model="AddInfo.collage_name"></el-input>
        </el-form-item>
        <el-form-item label="隶属学校">
          <el-input style="display:inline-block;width:33%;" v-model="AddInfo.school_name"></el-input>
        </el-form-item>
          <el-form-item label="状态">
            <el-input style="display:inline-block;width:33%;" v-model="AddInfo.status"></el-input>
          </el-form-item>
            <el-form-item label="可选操作">
              <el-input style="display:inline-block;width:33%;" v-model="AddInfo.profession_is_Enabled"></el-input>
        </el-form-item>
      </el-form>
      <!-- 按钮确定和取消 -->
      <span slot="footer">
        <el-button type="primary" @click.native="bao1AddSure">确定</el-button>
        <el-button @click.native="bao1newadd = false">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>



<script>
  export default {
    data() {
      return {
        biaoData: [],
        currentPage: 1,
        pagesize: 10,
        bao1look: false,
        bao1edit: false,
        bao1detele: false,
        bao1newadd: false,
        idx: null,
        deleteAll: [],
        del_list: [],
        select_word: "",
        //   定义初始信息
        LookInfo: {
          profession: "",
          collage_name: "",
          school_name: "",
          profession_is_Enabled:"",
          status:""
        },
        EditInfo: {
          profession: "",
          collage_name: "",
          school_name: "",
          profession_is_Enabled:"",
          status:""
        },
        AddInfo: {
          profession: "",
          collage_name: "",
          school_name: "",
          profession_is_Enabled:"",
          status:""
        }
      };
    },
    mounted() {
      this.getbiaoData();
    },
    methods: {
      //   得到所有的数据---------------
      getbiaoData() {
        this.$fetch("/biao1", {}).then(respone => {
          this.biaoData = respone.data.projects;
        });
      },
      // 分页------------------------
      // 初始页currentPage、初始每页数据数pagesize和数据data
      handleSizeChange: function(size) {
        this.pagesize = size;
      },
      handleCurrentChange: function(currentPage) {
        this.currentPage = currentPage;
      },
      // 操作界面 ----------- 查看
      // 当点击查看时，让dialog显示,同时赋值数据
      handleClick(index, row) {
        this.bao1look = true;
        this.LookInfo = {
          name: row.name,
          date: row.date,
          address: row.address
        };
      },
      // 操作界面 ----------- 编辑-----通过改变数据并且驱动视图更新$set方法
      handleEdit(index, row) {
        this.idx = profession;
        this.bao1edit = true;
        this.EditInfo = {
          name: row.name,
          date: row.date,
          address: row.address
        };
      },
      // 操作界面 ----------- 编辑 -------确定按钮
      bao1editSure() {
        this.$set(this.data, this.idx, this.EditInfo);
        this.bao1edit = false;
        this.$message.success("修改成功");
      },
      // 操作界面 ----------- 删除 -------
      handleDelete(index, row) {
        this.bao1detele = true;
        this.idx = profession;
      },
      // 操作界面 ----------- 删除 -------确定按钮
      bao1DeteleSure() {
        this.data.splice(this.idx, 1);
        this.bao1detele = false;
        this.$message.warning("删除成功");
      },
      // 新增按钮-----
      baonewAdd() {
        this.bao1newadd = true;
      },
      // 新增按钮----- 新增 ----确定按钮
      bao1AddSure() {
        //this.$refs.AddInfo 这个数据上有一个validate方法,这个方法可以判断数据是否存在
        this.$refs.AddInfo.validate(valid => {
          if (valid) {
            // 删除尾部数据，并且在头部添加
            this.data.pop();
            this.data.unshift(this.AddInfo);
            this.bao1newadd = false;
            this.$message.success("新增用户成功");
          }
        });
      },
      // 当用户手动勾选数据行的 Checkbox 时触发的事件, 将所有的勾选的数据集中到一个数组中
      select(selection, row) {
        this.deleteAll = selection;
      },
      // 批量删除-----all
      baodeleteAll() {
        // console.log(this.deleteAll);
        if (this.deleteAll.length) {
          this.del_list = this.del_list.concat(this.deleteAll);
          this.deleteAll = [];
          this.$message.success("删除成功");
        } else {
          this.$message.warning("请选择删除目标");
        }
      }
    },
    computed: {
      data() {
        return this.biaoData.filter(item => {
          // return item;
          let is_del = false;
          for (let i = 0; i < this.del_list.length; i++) {
            if (item.name === this.del_list[i].name) {
              is_del = true;
              break;
            }
          }
          if (!is_del) {
            if (
              item.name.indexOf(this.select_word) > -1 ||
              item.address.indexOf(this.select_word) > -1
            ) {
              return item;
            }
          }
        });
      }
    }
  };
</script>


<style scoped>
  .colhead {
    padding-bottom: 10px;
    border-bottom: 1px solid #ccc;
  }
</style>
